package com.briup.smartcity.web.controller;

import com.briup.smartcity.service.IBaseUserService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "登录模块")
//@RequestMapping("/auth/login")
@RestController
public class LoginController {
    @Autowired
    private IBaseUserService service;

    @ApiOperation("登录系统")
    @PostMapping(value = "/login",consumes = "application/x-www-form-urlencoded")
    public Result login(String username,String password){
        //调用service层
        String token = service.login(username,password);

        return ResultUtil.success(token);
    }
    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result loginOut(@ApiIgnore @RequestHeader("Authorization") String token){

        service.loginout();
        return ResultUtil.success();
    }
}
